package com.rcloud.stock;

import android.os.Bundle;

import com.google.android.material.bottomnavigation.BottomNavigationView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import java.util.Objects;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        BottomNavigationView navView = findViewById(R.id.nav_view);
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
        NavigationUI.setupWithNavController(navView, navController);
    }

    @Override
    public void onBackPressed() {
        NavController controller = Navigation.findNavController(this,R.id.nav_host_fragment);
        if (Objects.requireNonNull(controller.getCurrentDestination()).getId()==R.id.homeFragment ||
                controller.getCurrentDestination().getId()==R.id.hqFragment||
                controller.getCurrentDestination().getId()==R.id.zxFragment){
            finish();
        }else{
            onSupportNavigateUp();
        }
    }

    @Override
    public boolean onSupportNavigateUp() {
        NavController controller = Navigation.findNavController(this,R.id.nav_host_fragment);
        return controller.navigateUp();
    }
}